package com.fengkai.filepost.pdfoutstream.test.example;

import org.junit.Test;

import java.util.*;

/**
 * @author Fengkai
 * @creat 2021/12/28
 */
public class day01 {

    @Test
    public void test01(){
        Scanner scanner = new Scanner(System.in);
        String input = scanner.nextLine();
        ArrayList<Character> objects = new ArrayList<>();
        for (int i = 0; i <input.length() ; i++) {
            objects.add( input.charAt(i));
        }
        String output = "";
        for (int i = input.length(); i > 0 ; i--) {
            output += input.charAt(i-1);
        }

        System.out.println(output);
    }
    //将一个英文语句以单词为单位逆序排放。例如“I am a boy”，逆序排放后为“boy a am I”
    //所有单词之间用一个空格隔开，语句中除了英文字母外，不再包含其他字符
    @Test
    public void test02(){
        Scanner scanner = new Scanner(System.in);
        StringBuilder sb = new StringBuilder(scanner.nextLine());
        ArrayList<String> strings = new ArrayList<>();
        int i = 0;
        int j = 0;
        while (true){
            i = sb.indexOf(" ", j);
            if (i == -1){
                j = sb.lastIndexOf(" ");
                String substring = sb.substring(j + 1);
                strings.add(substring);
                break;
            }
            String substring = sb.substring(j, i);
            strings.add(substring);
            j = i + 1;
        }
        StringBuilder output = new StringBuilder();
        for (int k = strings.size()-1; k >= 0 ; k--) {
            output.append(strings.get(k) + " ");
        }
        System.out.println(output.substring(0, output.lastIndexOf(" ")));

    }


    @Test
    public void test03(){
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        String [] s = str.split(" ");

        System.out.println(Arrays.toString(s));
        int k = s.length - 1;
        StringBuilder output = new StringBuilder();

        for ( ; k >= 0 ; k--) {
            output.append(s[k]).append(" ");
        }
        output.substring(0, output.lastIndexOf(" "));
        System.out.println(output);
    }

    @Test
    //输入描述：
    //输入第一行为一个正整数n(1≤n≤1000),下面n行为n个字符串(字符串长度≤100),字符串中只含有大小写字母。
    //输出描述：
    //数据输出n行，输出结果为按照字典序排列的字符串。
    //示例1
    public void test04(){
        Scanner sc = new Scanner(System.in);
        ArrayList<String> strings = new ArrayList<>();
        int n = sc.nextInt();
        for (int i =0 ;i <n ;i++) {
            strings.add(sc.next());
        }
        Collections.sort(strings);

        strings.stream().forEach( s->{

            System.out.println(s);
        });

        Iterator<String> iterator = strings.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }

    }
}
